package com.syni.mdd.yhd.common.all.controller.protect;

import com.alibaba.fastjson.JSON;
import com.syni.mdd.sjb.common.component.utils.common.constants.CommonResultCode;
import com.syni.mdd.sjb.common.component.utils.common.annotations.EntranceCheck;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.constants.ResultCode;
import com.syni.mdd.yhd.common.all.dto.requestDto.userOpinion.OpinionReDto;
import com.syni.mdd.yhd.common.all.service.BmsUserOpinionService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.yhd.common.all.utils.StringUtils;
import com.syni.mdd.yhd.common.all.validationGroup.GroupInsert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/userOpinion")
public class BmsUserOpinionController {

    @Autowired
    BmsUserOpinionService bmsUserOpinionService;

    /**
     * @Description: 用户反馈
     * @return: Map
     * @Author: cfx
     * @Date: 2019/4/8
     */
    @EntranceCheck
    @PostMapping("/feedback")
    public Map<String,Object> feedback(@RequestBody @Validated(value = {GroupInsert.class}) OpinionReDto opinionReDto){
        if(StringUtils.isNotBlank(opinionReDto.getExtraImg())) {
            List<String> imgList = (List<String>) JSON.parse(opinionReDto.getExtraImg());
            if (imgList.size() > 10) {
                return ResultMapHelper.result(ResultCode.CODE_ERROR_03, "上传图片超过限制");
            }
        }
        return bmsUserOpinionService.feedback(opinionReDto);
    }


    @EntranceCheck(checkAuth = true)
    @PostMapping("/feedbackByMinApp")
    public Map<String,Object> feedbackByMinApp(@RequestBody OpinionReDto opinionReDto){
        opinionReDto.setFromOrigin(Constants.WECHAT_MINAPP);
        if(StringUtils.isBlank(opinionReDto.getContent())){
            return ResultMapHelper.result(ResultCode.CODE_ERROR_100,"请输入反馈内容");
        }
        return bmsUserOpinionService.feedback(opinionReDto);
    }
}
